jQuery(function() {
    trainer_scroll_bar();
    pre_recorded_scroll_bar();
})

function trainer_scroll_bar() {
    if(jQuery('#scrollbar1').length > 0) {
        var height = jQuery('#scrollbar1 #trainer-online').height();
        if(height > 360) {
          jQuery('#scrollbar1 .viewport').height(360);
          jQuery('#scrollbar1 .thumb').show();
          jQuery('#scrollbar1 .scrollbar').show();
          jQuery('#scrollbar1').tinyscrollbar();
        } else {
          jQuery('#scrollbar1 .scrollbar').hide();
          jQuery('#scrollbar1 .thumb').hide();
          jQuery('#scrollbar1 .viewport').height(height);
        }
    }
}

function pre_recorded_scroll_bar() {
    if(jQuery('#scrollbar2').length > 0) {
        var height = jQuery('#scrollbar2 #pre-recorded').height();
        if(height > 260) {
          jQuery('#scrollbar2 .viewport').height(260);
          jQuery('#scrollbar2 .thumb').show();
          jQuery('#scrollbar2 .scrollbar').show();
          jQuery('#scrollbar2').tinyscrollbar();
        } else {
          jQuery('#scrollbar2 .thumb').hide();
          jQuery('#scrollbar2 .scrollbar').hide();
          jQuery('#scrollbar2 .viewport').height(height);
        }
    }
}


function trainer_search() {
    var url = 'http://' + location.hostname + Drupal.settings.basePath;
    var male;
    var female;
    if(jQuery('#tr-male').is(':checked')) {
        male = jQuery('#tr-male').val();
    } else {
        male = -1;
    }
    if(jQuery('#tr-female').is(':checked')) {
        female = jQuery('#tr-female').val();
    } else {
        female = -1;
    }
    var genre = jQuery('#tr-genre').val();
    var cost = jQuery('#tr-cost').val();
    jQuery.post(url + 'search-trainer', {male: male, female: female, genre: genre, cost: cost}, function(data) {;
                if(data) {
                    jQuery('#trainer-online').html(data);
                } else {
                    jQuery('#trainer-online').html('No result found !');
                }
                trainer_scroll_bar();
            });
}

function pre_recorded_search() {
    var url = 'http://' + location.hostname + Drupal.settings.basePath;
    var male;
    var female;
    if(jQuery('#re-male').is(':checked')) {
        male = jQuery('#re-male').val();
    } else {
        male = -1;
    }
    if(jQuery('#re-female').is(':checked')) {
        female = jQuery('#re-female').val();
    } else {
        female = -1;
    }
    var genre = jQuery('#re-genre').val();
    var cost = jQuery('#re-cost').val();
    jQuery.post(url + 'search-pre-recorded', {male: male, female: female, genre: genre, cost: cost}, function(data) {
                if(data) {
                    jQuery('#pre-recorded').html(data);
                } else {
                    jQuery('#pre-recorded').html('No result found !');
                }
                pre_recorded_scroll_bar();
            });
}